//
//  CommonAPI.swift
//  LeGou
//
//  Created by lxm on 2022/7/23.
//
import Foundation

enum CommonAPI {
    // 城市列表
    case cityList
    // 上传图片
    case uploadImg(_ img: UIImage)
    // 查看物流
    case queryExpress(_ orderId: String)
    // 获取文章内容
    case getDetail(_ id: Int)
    // 初始化信心
    case appInitInfo
    
    case ad
    // 获取支付配置
    case paySetting
}

extension CommonAPI: ZMApiProvider {
    
    func BaseUrl() -> String {
        return baseUrl
    }
 
    func urlAndMthodAndParam() -> (url: String, method: ZMHTTPMethod, params: [String : Any], body: Bool) {
        switch self {
            case .cityList:
                return ("/api/front/city/list", .get, [:], false)
            case .uploadImg:
                return ("/api/front/user/upload/image?model=user&pid=7", .post, [:], true)
            case .queryExpress(let orderId):
                return ("/api/front/order/express/\(orderId)", .get, [:], false)
            case .getDetail(let id):
                return ("/api/front/article/info", .get, ["id":id], false)
            case .appInitInfo:
                return ("/api/front/app/init", .get, [:], false)
            case .ad:
                return ("/api/front/banner/getAdvertisement", .get, [:], false)
            case .paySetting:
                return ("/api/front/order/get/pay/config", .get, [:], false)
            
        }
    }
    
    func HTTPHeader() -> ZMHTTPHeaders? {
        return AppHelper.reqeustHeader()
    }
    
    func UpLoadData() -> [Data]? {
        switch self {
        case .uploadImg(let img):
            return [img.jpegData(compressionQuality: 0.5)!]
        default:
            return nil
        }
    }
}
